*------------------------------------------------------------
* Script : Sample-Serial Port Communication
* Date : 1st February 2003
* Notes : Sample script for Xtend IVR Toolkit.
*------------------------------------------------------------
; Query modem parameter using the AT commands
:MAIN
answer
; each AT command is terminated by <CRLF><LINE FEED>
$CR = chr(13)
$NL = chr(10)
; Opens COM1 where the voice modem is expected
; Baud rate is set as 9600
; N81 - No Parity, 8 data bits, 1 Stop bit
if ComOpen("COM1", "9600 N81 none")
; Issue the AT&V command to modem
ComWrite("at&v")
ComWrite($CR)
ComWrite($NL)
; Get the size of data returned by modem
$size = ComReadSize()
; Read the data streamed by the modem
while $size > 0
; Modem is a slow device.
; So wait for 2000 milliseconds for the data to arrive in the port
$buffer = ComReadLine(2000)
display $buffer
log $buffer
Sleep 1000
;See for pending data size to be read
$size = ComReadSize()
endwhile
; Done. Close the port and quit
ComClose()
endif
hangup
goto MAIN
:ONSYSTEMERROR
log $error
hangup
goto MAIN
- A
connection is established with the serial port, COM1, where the voice modem
(here) is connected. Port settings include a baudrate of 9600 bits per second
having 'N' (ie., no) parity check, 8 bits constituting a byte, 1 set as the
stop bit with no flow control. If the voice modem (here) is connected, then
write the AT command to get the modem parameters. The size of the data to be
read is found out. If the variable $size is not empty, then read each line of
the data with a timeout of 2 seconds. The read data is then displayed. Then
we log the read data. The serial port is checked for remaining data. If any,
they are read. Then connection with the serial port is closed and control will
return to the MAIN function.
See also ComOpen(),
ComReadSize()
ComReadLine(),
ComWrite(),
ComClose().